#ifndef PKGDESC_H
#define PKGDESC_H

#include "md4.h"
#include <tchar.h>
#include <string.h>
#include "pkg.h"

class Client;
class AdminPipe;

class PackageDescription
{
	public:
		PackageDescription();
		PackageDescription(const String& pkgname, uint32 version, const String& zipfile);
		~PackageDescription();

		bool8 set(const String& pkgname, uint32 version, const String& zipfile);

		uint32	getSendSize();
		bool8	send(Client* client, bool8 unicode=false);

		uint32	getAdminSendSize();
		bool8	adminSend(AdminPipe* client, bool8 unicode=false);

		const String&	getName();
		uint32	getVersion();
		const String& getVersionStr(); // CSN-7534: String version
		const String&	getZipName();
		uint32	getZipSize();
		void	setUnknown();

		PackageDescription*	getNext();
		void				setNext(PackageDescription* Next);

		TCHAR* getContents();
		uint32	getNumFiles();
		uint32	getUnzippedPkgSize();
		t_md4	*getStrongChecksums();

		uint8			getNumDependencies();
		PkgDependency*	getDepencies();

		bool8 setZipFile(const String& Zip);		//reads information from zip

		void copy(PackageDescription*);

	protected:
		bool8 	FindZipContents();
		bool8	FindTotalPackageSize();
		bool8	FindStrongChecksums();
		bool8	FindDependencies();
		pCStream FindUnzippedFile(const String& filename);
		bool8 FindStrongChecksum(pCStream file, t_md4 *md4);

	protected:
		Package				pkg;
		PackageDescription* next;
		uint32				adminSendSize;
		String				zipfile;

		// this is a list of the filenames contained in the zip file
		//  stored contiguously as null terminated strings with a 
		//  null string terminator (a string of length zero).  this is 
		//  calculated upon creation of this package description.
		TCHAR*				m_contents;
		uint32				m_num_files;

		t_md4				*m_strong_checksums;
        int32               m_refCount;
};

inline
PackageDescription::~PackageDescription()
{
	delete [] m_contents;
	m_contents = (TCHAR *)0;
	delete [] m_strong_checksums;
	m_strong_checksums = (t_md4 *)0;
}

inline uint32
PackageDescription::getAdminSendSize()
{
	return adminSendSize;
}

inline const String&
PackageDescription::getName()
{
	return pkg.getName();
}

inline uint32
PackageDescription::getVersion()
{
	return pkg.getLocalVersion();
}

inline const String&
PackageDescription::getVersionStr()
{
	return pkg.getVersionStr();
}

inline const String&
PackageDescription::getZipName()
{
	return zipfile;
}

inline uint32
PackageDescription::getZipSize()
{
	return pkg.getZipSize();
}

inline PackageDescription*
PackageDescription::getNext()
{
	return next;
}

inline void				
PackageDescription::setNext(PackageDescription* Next)
{
	next = Next;
}


inline TCHAR*
PackageDescription::getContents()
{
	return m_contents;
}

inline uint32	
PackageDescription::getNumFiles()
{
	return m_num_files;
}

inline uint32	
PackageDescription::getUnzippedPkgSize()
{
	return pkg.getUnZipSize();
}

inline t_md4 *
PackageDescription::getStrongChecksums()
{
	return m_strong_checksums;
}

inline uint8
PackageDescription::getNumDependencies()
{
	return pkg.getNumDependency();
}

inline PkgDependency*
PackageDescription::getDepencies()
{
	return pkg.getDependencies();
}


#endif
